﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ProjectIndieFarm
{
    public class PowerUp : IPowerUp
    {
        public string Key { get; set; }
        public string Title { get; set; }
        public string Description { get; set; }
        public int Price { get; set; }
        public bool Unlocked { get; set; }

        private Func<PowerUp, bool> mCondition;
        private Action<PowerUp> mOnUnlock;

        public void OnUnlock()
        {
            Unlocked = true;
            PowerUpSystem.PowerUpHadUnlockedToday.Value = true;
            mOnUnlock?.Invoke(this);
        }

        public bool ShowCondition()
        {
            return !Unlocked && (mCondition == null || mCondition(this));
        }

        public void SendMessageWithEffect(string effect)
        {
            UIMessageQueue.Push($"[<color=black>{Title}</color>] 强化成功! <color=green>{effect}</color>");
        }

        #region set method
        public PowerUp SetKey(string key)
        {
            Key = key;
            return this;
        }
        public PowerUp SetTitle(string title)
        {
            Title = title;
            return this;
        }
        public PowerUp SetDescription(string description)
        {
            Description = description;
            return this;
        }
        public PowerUp SetPrice(int price)
        {
            Price = price;
            return this;
        }

        public PowerUp ShowCondition(Func<PowerUp, bool> condition)
        {
            mCondition = condition;
            return this;
        }
        public PowerUp OnUnlock(Action<PowerUp> onUnlock)
        {
            mOnUnlock = onUnlock;
            return this;
        }
        #endregion
    }
}
